// index.js
// 获取应用实例
import Notify from '@vant/weapp/notify/notify';
const app = getApp()
Page({
  data: {
    //搜索内容
    value: '',
    //轮播图
    swiperList: [{
      id: 0,
      type: 'image',
      url: 'http://fileapi.wechat.copyctrl.top/data/upload/show/campus5.jpg'
    }, {
      id: 1,
        type: 'image',
        url: 'http://fileapi.wechat.copyctrl.top/data/upload/show/campus1.jpg'
    }, {
      id: 2,
      type: 'image',
      url: 'http://fileapi.wechat.copyctrl.top/data/upload/show/campus2.jpg'
    }, {
      id: 3,
      type: 'image',
      url: 'http://fileapi.wechat.copyctrl.top/data/upload/show/campus3.jpg'
    }, {
      id: 4,
      type: 'image',
      url: 'http://fileapi.wechat.copyctrl.top/data/upload/show/campus4.jpg'
    }, {
      id: 5,
      type: 'image',
      url: 'http://fileapi.wechat.copyctrl.top/data/upload/show/campus0.jpg'
    }],
    //功能按钮
    list: [{
      text: "校园资讯",
      url: "https://fileapi.wechat.copyctrl.top/data/upload/icon/text.png",
      id: 0
    },
    {
      text: "跳蚤市场",
      url: "https://fileapi.wechat.copyctrl.top/data/upload/icon/shop.png",
      id: 1
    },
    {
      text: "失物招领",
      url: "https://fileapi.wechat.copyctrl.top/data/upload/icon/lost.png",
      id: 2
    },
    {
      text: "互助",
      url: "https://fileapi.wechat.copyctrl.top/data/upload/icon/help.png",
      id: 3
    },
    {
      text: "我的订单",
      url: "https://fileapi.wechat.copyctrl.top/data/upload/icon/order.png",
      id: 4
    },
    {
      text: "交友广场",
      url: "https://fileapi.wechat.copyctrl.top/data/upload/icon/makefriends.png",
      id: 5
    }, {
      text: "通知公告",
      url: "https://fileapi.wechat.copyctrl.top/data/upload/icon/an.png",
      id: 6
    },
    {
      text: "个人空间",
      url: "https://fileapi.wechat.copyctrl.top/data/upload/icon/mine.png",
      id: 7
		}],
		//热点资讯
    hot:[],
    loadModal:true
  },
  
  onLoad() {
   
  },
  onShow() {
		this.getTabBar().init();
		this.getHots()
  },
  //跳转到资讯界面
  gotoSome(e) {
    console.log(e.currentTarget.dataset.id)
    let page=e.currentTarget.dataset.id
    if(page==0){
      //全部资讯
      wx.navigateTo({
        url: '/pages/index/all/all',
      })
    }else if(page==1){
			//跳蚤市场
			wx.navigateTo({
        url: '/pages/index/shop/shop',
      })
		}else if(page==2){
			//失物招领
			wx.navigateTo({
        url: '/pages/index/found/found',
      })
		}else if(page==4){
			//失物招领
			wx.navigateTo({
        url: '/pages/index/order/order',
      })
		}else if(page==3){
			//互助
			wx.navigateTo({
        url: '/pages/index/question/question',
      })
		}else if(page==5){
			wx.navigateTo({
				url: '/pages/index/friend/friend',
			})
		}else if(page==6){
			wx.navigateTo({
				url: '/pages/index/announce/announce',
			})
		}else if(page==7){
			var user=wx.getStorageSync('user')
			wx.navigateTo({
				url: '/pages/show/show?id='+user.id,
			})
		}
	},
	//获取热点文章
	getHots(){
		app.request({
      url: app.globalData.apiUrl + '/passage/hot' ,
      method: 'GET',
    }).then(res => {
      if (res.statusCode == 200) {
				this.setData({
          hot:res.data.data,
          loadModal:false
				})
      } else {
        this.setData({
          loadModal:false
        })
      }
    })
	},
	search(){
    this.setData({
      loadModal:true
    })
		app.request({
      url: app.globalData.apiService + '/search/get/' + this.data.value,
      method: 'GET',
    }).then(res => {
      if (res.statusCode == 200) {
				var getData=res.data.data
				wx.navigateTo({
					url: '/pages/index/search/search?data='+JSON.stringify(getData),
				})
				this.setData({
          value:'',
          loadModal:false
				})
      } else {
        this.setData({
          loadModal:false
        })
        Notify('服务错误，稍后重试');
      }
    })
	},
	onChange(e){
		this.setData({
			value:e.detail
		})
	},
	gotoPassage(e) {
		console.log(e.currentTarget.dataset.id)
		wx.navigateTo({
			url: '/pages/index/passage/passage?id=' + e.currentTarget.dataset.id,
		})
	}
})